#include "student.h"
#include <cstring>
#include <stdio.h>

struct StudentPrivate
{
    StudentPrivate(const char* name, int age):grade(16),age(age)
    {
        int len = strlen(name);
        this->name = new char[len + 1];
        strcpy(this->name, name);
    };
    ~StudentPrivate()
    {
        delete name;
    }
    StudentPrivate(StudentPrivate &stu);
    int age;
    char* name;
    const int grade;
};

StudentPrivate::StudentPrivate(StudentPrivate &stu):grade(stu.grade)
{
    age = stu.age;
    name = new char(strlen(stu.name) +1);
    strcpy(name, stu.name);
}

int Student::count = 0;
Student::Student(const char* name, int age)
{
    p = new StudentPrivate(name, age);
    count++;
    printf("create a  Student!\n");
}

Student::Student(Student& stu)
{
    printf("student(student &student)\n");
    p = new StudentPrivate(*stu.p);
}


Student::~Student()
{
    count --;
    printf("kill a student!\n");
    delete p;
}

void Student::print()
{
    printf("name:%s\n", p->name);
    printf("age:%d\n", p->age);
}